package main

import (
	"game-handker/api/dbinit"
	"game-handker/pkg/sms"

	"game-handker/api"
	"game-handker/internal/config"
	"game-handker/pkg/redis"

	"github.com/gin-gonic/gin"
)

func main() {

	router := gin.Default()

	cfg := config.LoadConfig()
	dbinit.Init()

	//阿里短信服务，手机验证码登陆
	if cfg.AlismsEnable {
		smsClient, err := sms.NewAliyunClient(cfg.AccessKeyID, cfg.AccessKeySecret)
		if err != nil {
			panic(err)
		}

		redisClient := redis.NewRedisClient(cfg.RedisAddr)
		router.GET("/send-code", api.SendCodeHandler(smsClient, redisClient))
		router.GET("/validate-code", api.ValidateCodeHandler(redisClient))

	}

	//注册和登陆
	router.POST("/register", api.Register())
	router.POST("/login", api.Login())
	router.POST("/renew-token", api.RenewTokenHandler())
	router.POST("/resources", api.QueryStaticResources())
	router.POST("/addResources", api.AddStaticResources())
	router.Run(cfg.ServerPort)
}
